<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
include_once( "member/proc_betin.php" );
$ui = new UI();
$tpl = new Template2();
$conf = new Config();
$news = $conf->Get("news_th");
if ($news == "")
{
    $news = $conf->Get("news");
}
else
{
    $news = "<font color=red>" . $news . "</font>&#12288;" . $conf->Get("news");
}
$tpl->set("account", $curruser['account']);
if ($curruser['enabled'] == 0 || $curruser['enabled'] == 2)
{
    $ui->showErrorPage("<p class=error>帐号已被暂停使用</p>");
    exit();
}
$rs = getdb("select * from lotto where open>='" . date("Y-m-d") . "' order by open");
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>目前没有可以下注期数！</p>");
    exit();
}
$open = $rs->f['open'];
$round = $rs->f['round'];
$lotto_id = $rs->f['id'];
$othebet = $conf->get("othebet");
$stopbet = $conf->get("stopbet");
$waitbet = $conf->get("waitbet");
if (date("Y-m-d") < $open)
{
    exit();
}
else if (date("Y-m-d") == $open)
{
    if ($stopbet <= date("Hi"))
    {
        $ui->showErrorPage("<p>下注期数：" . d3($round) . "<br>开奖日：" . $open . "</p>" . "<p class=error>已经截止下注！</p>");
        exit();
    }
    else if (date("Hi") <= $conf->get("startbet"))
    {
        exit();
    }
}
$t1 = strtotime($open . " " . $stopbet);
$tpl->Set("timestap", $t1 - systime());
$tpl->set("open", $open);
$tpl->set("round", d3($round));
$tpl->set("lotto_id", $lotto_id);
$tpl->set("account", $curruser['account']);
$tpl->set("amount", $curruser['amount']);
$idisk=getUserValidDisk($curruser);
$disk = $g_disk_code[$idisk];

$rates = array();
$rs0 = getdb("select * from rate0" . $disk . " where lotto_id={$lotto_id}");
if ($rs0->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$rates += $rs0->f;
$rs1 = getdb("select * from rate1" . $disk . " where lotto_id={$lotto_id}");
if ($rs1->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$rates += $rs1->f;
$rs5 = getdb("select * from rate5" . $disk . " where lotto_id={$lotto_id}");
if ($rs5->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$rates += $rs5->f;
$rs15 = getdb("select * from rate15" . $disk . " where lotto_id={$lotto_id} limit 1");
if ($rs15->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$rates += $rs15->f;
$rs15->close();
$rs49 = getdb("select r0 as r49_0,r1 as r49_1,r2 as r49_2,r3 as r49_3,r4 as r49_4 from rate37 where lotto_id={$lotto_id} and bettype=49 and disk=".$idisk." limit 1");
if ($rs49->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$rates += $rs49->f;
$rs49->close();
$rs50 = getdb("select r0 as r50_0,r1 as r50_1,r2 as r50_2,r3 as r50_3,r4 as r50_4,r5 as r50_5,r6 as r50_6,r7 as r50_7,r8 as r50_8,r9 as r50_9 from rate37 where lotto_id={$lotto_id} and bettype=50 and disk=".$idisk." limit 1");
if ($rs50->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$rates += $rs50->f;
$rs50->close();
$rs->close();
$betmin = $conf->get("betmin");
$tpl->set("min", $betmin);
$betmax = $conf->get("betmax");
$tpl->set("max", $betmax);
$tpl->set("max_str", $betmax);
$rs = getdb("select amount_6h from k_user_bet where user_id=" . $curruser['id'] . " and lotto_id=" . $lotto_id);
$usedamount = $rs->f[0] ? $rs->f[0] : 0;
$rs->close();
$limit = array();
$limit[0] = GetAmountInfo(0);
$limit[1] = GetAmountInfo(1);
$limit[2] = GetAmountInfo(2);
$limit[3] = GetAmountInfo(3);
$limit[5] = GetAmountInfo(5);
$limit[6] = GetAmountInfo(6);
$limit[13] = GetAmountInfo(13);
$limit[14] = GetAmountInfo(14);
$limit[20] = GetAmountInfo(20);
$limit[24] = GetAmountInfo(24);
$limit[28] = GetAmountInfo(28);
$limit[30] = GetAmountInfo(30);
$limit[46] = GetAmountInfo(46);
$limit[47] = GetAmountInfo(47);
$limit[15] = GetAmountInfo(15);
$limit[49] = GetAmountInfo(49);
$limit[50] = GetAmountInfo(50);
$ok = isset($_POST['tnumber']);
if ($ok)
{
    echo "<body>";
}
else
{
    echo "<body onload='StartFocus()'>";
}
echo "<form action=\"op.php?op=member&fp=proc51".(empty($_GET['back'])?"":"&back=".$_GET['back'])."\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
echo "<input type=hidden name=disk value=" . strpos(" abcd", $disk) . ">";
$waittime = 2000;
$betcount = 0;
$total = 0;
$tmp = "";
$oddname = array("", "单", "双");
$bigname = array("", "大", "小");
$bigmidsmall = array("", "大", "中", "小");
$chinayearname = array("", "家禽", "野兽");
$colorname = array("", "红波", "蓝波", "绿波");
$zmnum = array("", "一", "二", "三", "四", "五", "六");
$usemaxamount = $curruser['usemaxamount'];
$user_rate0 = get_share_rate0($curruser['id']);
$rate0_8num = get_share_rate0_8($curruser['id']);
$user_rate8 = $user_rate0 * $rate0_8num;
$u2 = get_user($curruser['prev_id']);
$u3 = get_user($u2['prev_id']);
$u4 = get_user($u3['prev_id']);
$u5 = get_user($u4['prev_id']);
$check = TRIM($_POST['check'],',');
$money = intval( $_POST['txtrmb'] );
$pieces = explode(",", $check); 
$nums_count = count($pieces);
asort($pieces);
foreach ($pieces as $key => $val)
{
    $val = intval($val);
    if (0 < $val)
    {		
		if($val<10){
			$val = '0'.$val;
		}
				$rs = getdb( "select r".$val." from rate0".$disk." where lotto_id=".$lotto_id );
				$sub_rates = get_subs_rates( $curruser['id'], $lotto_id, 0, $val );
				$rate = $rs->f[0] - $sub_rates - $user_rate0 - 0;
				$tmp .= "<tr class=td2>";
                $tmp .= "<td>特码</td>";
				$tmp .= "<td>" . $val . "</td>";
                $tmp .= "<td align=right>" . $rate . "</td>";
                $tmp .= "<td align=right>" . $money . "</td>";
                $tmp .= "</tr>";
        
    }
}
$total =$nums_count * $money;
if ($money == 0)
{
    $ui->showErrorPage("<p>请输入下注金额！</p>" . ( "<p><input type=button value='回上一页' onclick='history.back()'></p>" ));
    exit();
}
echo "您下注的是：" . strtoupper($disk) . " 盘";
echo "<div style='overflow:auto;overflow-x:hidden;height:450px; width:230px;'>";
echo "<table border=0 cellpadding=2 cellspacing=1 class=table0>";
echo "<tr class=td0><td>下注方式</td><td>下注内容</td><td>赔率</td><td>下注金额</td>";
/* if ($ok)
{
    echo "<td>结果</td>";
} */
echo "</tr>";
echo $tmp;
echo "<tr class=td0 align=right><td colspan=3>合计</td><td>" . $total . "" . ( $ok ? "</td>" : "" ) . "</tr>";
echo "</table>";

echo "<input type=hidden name=money value=".$money.">";
echo "<input type=hidden name=check value=".$check.">";
echo "<input type=hidden name=total value=".$total.">";
    echo "<br>";
    echo "<input type=submit name=submit value=确定下注>&#12288;<input name=reset type=reset value=取消下注 onclick='history.back()'>";
    echo "</form>";
	echo "</div>";
    echo "<Script>function StartFocus(){  document.forms[0].submit.focus();}</Script>";
    echo "</body>";
function getZmName($type)
{
	$betname=$type;
	switch ($type)
	{
		case 1 :
			$betname = "单";
			break;
		case 2 :
			$betname = "双";
			break;
		case 3 :
			$betname = "大";
			break;
		case 4 :
			$betname = "小";
			break;
		case 5 :
			$betname = "红";
			break;
		case 6 :
			$betname = "蓝";
			break;
		case 7 :
			$betname = "绿";
			break;
		case 8 :
			$betname = "合单";
			break;
		case 9 :
			$betname = "合双";
	}	
	return $betname;
}
?>